﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SHDServer
{
    /// <summary>
    /// 语音广播类
    /// </summary>
    internal class VoiceBroadcast
    {
        private VoiceBroadcast()
        { }

        private SocketServer m_svr = null;

        public VoiceBroadcast(SocketServer svr)
            : this()
        {
            this.m_svr = svr;
        }

        /// <summary>
        /// 开始侦听扫码订单语音服务
        /// </summary>
        public void StartToBroadcaseScanOrder()
        {
            while (true)
            {
                if (IsHaveNewScanCodeOrder())
                {
                    //广播语音到各个客户端
                    byte[] responseSpeach = CommHelper.NetworkDataHelper.GetNetworkDataHelper.GetResponseBytes(
                        CommData.MessageStatus.Success,
                        "Broadcasting",
                        CommHelper.ConvertHelper.ConventStringToSpeakByte(GlobalData.ScanCodeOrderSpeechText),
                        0);
                    m_svr.SendResponseAll(responseSpeach);
                }
                System.Threading.Thread.Sleep(GlobalData.ScanCodeOrderSpeechInterval * 1000);
            }
        }

        /// <summary>
        /// 是否存在新的扫码订单
        /// </summary>
        /// <returns></returns>
        private bool IsHaveNewScanCodeOrder()
        {
            return GlobalData.ScanCodeOrders.Count > 0;
        }

        /// <summary>
        /// 获取所有未下单的扫码订单
        /// </summary>
        /// <returns></returns>
        private List<long> GetAllScanCodeOrders()
        {
            List<long> lstScanCodeOrders = new List<long>();

            return lstScanCodeOrders;
        }
    }
}